package com.cloud.cloudorder.order.config.rabbitmq;

import com.cloud.common.constant.RabbitmqOrderConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author : Luojie
 * @CreateTime : 2019/9/3
 * @Description :
 **/
@Configuration
public class FanoutRabbitConfig {
 
    //队列 起名：OrderFanoutQueue
    @Bean
    public Queue OrderFanoutQueue() {
        //true 是否持久
        return new Queue(RabbitmqOrderConstants.ORDER_FANOUT_QUEUE,true);
    }
 
    //Fanout交换机 起名：OrderFanoutExchange
    @Bean
    FanoutExchange OrderFanoutExchange() {
        return new FanoutExchange(RabbitmqOrderConstants.ORDER_FANOUT_EXCHANGE);
    }
 
    //绑定  将队列和交换机绑定, 并设置用于匹配键：OrderFanoutRouting
    @Bean
    Binding bindingFanout() {
        return BindingBuilder.bind(OrderFanoutQueue()).to(OrderFanoutExchange());
    }

}